# This file is used to check for python dependencies and install them to the user
# It's written by: (C) J.Y.Amihud ( and contributers ) 2022 and is under the GNU
# General Public License version 3 or any later version as published by the Free
# Software Foundation.

import os
import json

clr = {
    "norm":"\033[00m", # Reset to normal
    "bold":"\033[01m", # Bold Text
    "ital":"\033[03m", # Italic Text
    "undr":"\033[04m", # Underlined
    "blnk":"\033[05m", # Blinking

    # Text
    "tdbl":"\033[30m", # Dark Black
    "tdrd":"\033[31m", # Dark Red
    "tdgr":"\033[32m", # Dark Green
    "tdyl":"\033[33m", # Dark Yellow
    "tdbu":"\033[34m", # Dark Blue
    "tdma":"\033[35m", # Dark Magenta
    "tdcy":"\033[36m", # Dark Cyan
    "tdwh":"\033[37m", # Dark White

    "tbbl":"\033[90m", # Bright Black
    "tbrd":"\033[91m", # Bright Red
    "tbgr":"\033[92m", # Bright Green
    "tbyl":"\033[93m", # Bright Yellow
    "tbbu":"\033[94m", # Bright Blue
    "tbma":"\033[95m", # Bright Magenta
    "tbcy":"\033[96m", # Bright Cyan
    "tbwh":"\033[97m", # Bright White
    # Background
    "bdbl":"\033[40m", # Dark Black
    "bdrd":"\033[41m", # Dark Red
    "bdgr":"\033[42m", # Dark Green
    "bdyl":"\033[43m", # Dark Yellow
    "bdbu":"\033[44m", # Dark Blue
    "bdma":"\033[45m", # Dark Magenta
    "bdcy":"\033[46m", # Dark Cyan
    "bdwh":"\033[47m", # Dark White

    "bbbl":"\033[100m", # Bright Black
    "bbrd":"\033[101m", # Bright Red
    "bbgr":"\033[102m", # Bright Green
    "bbyl":"\033[103m", # Bright Yellow
    "bbbu":"\033[104m", # Bright Blue
    "bbma":"\033[105m", # Bright Magenta
    "bbcy":"\033[106m", # Bright Cyan
    "bbwh":"\033[108m"  # Bright White
}

def run():
    with open('TROUBLESOME_MODULES.json') as json_file: 
        data = json.load(json_file)

    for module in data:

        try:
            e = "import "+module
            exec(e)
        except:
            print()
            print("    "+clr["bdrd"]+" Python Module '"+module+"' is not installed! "+clr["norm"])
            print("    The module is needed for: "+data[module]["reason"])
            print("    It's source code is available at: "+data[module]["source"])
            print("    And it's licensed under: "+data[module]["license"])
            print()
            print("    "+clr["bdgr"]+" WOULD YOU LIKE TO INSTALL IT? (yes/no) "+clr["norm"])
            print()

            yesno = input(":")

            if yesno.lower() in ["y", "yes"]:
                os.system(data[module]["install"])
            else:
                return

if __name__ == "__main__":
    run()
